package com.zky.domain.po;

import lombok.Data;

@Data
public class  Result<T> {
    private int code;
    private String msg;
    private T data;

    // 私有化构造函数，统一使用静态方法构建
    private Result() {}

    private Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 成功响应，默认 msg 为 "success"
    public static Result ok() {
        return new Result(200, "success", null);
    }

    public static <T>Result ok(T data) {
        return new Result(200, "success", data);
    }

    public static <T>Result ok(String msg, T data) {
        return new Result(200, msg, data);
    }

    // 失败响应，默认 msg 为 "error"
    public static Result fail() {
        return new Result(500, "error", null);
    }

    public static Result fail(String msg) {
        return new Result(500, msg, null);
    }

    public static Result fail(int code, String msg) {
        return new Result(code, msg, null);
    }

    // 链式设置方法（可选）
    public Result code(int code) {
        this.code = code;
        return this;
    }

    public Result msg(String msg) {
        this.msg = msg;
        return this;
    }

    public Result data(T data) {
        this.data = data;
        return this;
    }
}
